#include "ili9325-fsmc.h"
#include "GUI.h"
#include "BUTTON.h"
#include "WM.h"
#include "EDIT.h"
#include "GUIDEMO.h"
#include "GUI_Debug.h"
#include "SPINBOX.h"

#ifdef  USE_FULL_ASSERT

/**
   * @brief  Reports the name of the source file and the source line number
   *         where the assert_param error has occurred.
   * @param  file: pointer to the source file name
   * @param  line: assert_param error line source number
   * @retval None
   */
void assert_failed(uint8_t* file, uint32_t line)
{
    /* User can add his own implementation to report the file name and line number,
      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

    /* Infinite loop */
    while (1)
    {
    }
}
#endif

static u32 cnt = 0;

GUI_PID_STATE state;

static void _cbBkWindow(WM_MESSAGE* pMsg) {
    GUI_RECT rect;

    switch (pMsg->MsgId) {
    case WM_PAINT:
        WM_GetInvalidRect(pMsg->hWin, &rect);
        GUI_SetBkColor(GUI_BLUE);
        GUI_ClearRectEx(&rect);
        break;
    case WM_TOUCH:
        //GUI_DispDecAt(cnt++, 110, 150, 4);
        GUI_TOUCH_GetState(&state);
        GUI_DrawPixel(state.x, state.y);
        break;
    default:
        WM_DefaultProc(pMsg);
    }
}

int main(void)
{
     BUTTON_Handle hB;
     EDIT_Handle hE;

     GUI_Init();
     GUI_SetBkColor(GUI_BLUE);
     GUI_Clear();
     hB = BUTTON_CreateEx(150, 0, 100, 50, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_OK);
     SPINBOX_CreateEx(70, 200, 100, 50, WM_HBKWIN, WM_CF_SHOW,
                      GUI_ID_SPINBOX0, 5, 2222);
     hE = EDIT_CreateEx(0, 0, 100, 30, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_EDIT0, 100);
     EDIT_SetText(hE, "HelloWorld");
     WM_SetCallback(WM_HBKWIN, _cbBkWindow);
     while (1) {
          GUI_TOUCH_Exec();
          GUI_Delay(1);
     }
}
